package com.spring.framwork.springmvc;

import com.spring.framwork.springmvc.annotation.ResponseBody;

import java.lang.reflect.Method;

public class WebHandler {
    private final Object ControllerBean;
    private final Method method;
    private final ResultType resultType;

    public WebHandler(Object controllerBean, Method method) {
        ControllerBean = controllerBean;
        this.method = method;
        this.resultType=resovleResultType(controllerBean,method);
    }

    private ResultType resovleResultType(Object controllerBean, Method method) {
        if (method.isAnnotationPresent(ResponseBody.class)){
            return ResultType.JSON;
        }
        if (method.getReturnType()== ModelAndView.class){
            return ResultType.LOCAL;
        }
        return ResultType.HTML;
    }

    public Object getControllerBean() {
        return ControllerBean;
    }

    public Method getMethod() {
        return method;
    }

    public ResultType getResultType() {
        return resultType;
    }

    enum ResultType{
        JSON,HTML,LOCAL;
    }
}
